{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# _Qubit Chain_\n",
    "\n",
    "<img src=\"images/line_qubits_site1.png\" alt=\"Qubit Chain\">"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Contributor\n",
    "Alexander Yu. Vlasov\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Here is used representation initially introduced for _perfect state transfer_. The chain with $n$ nodes is modeled by $n$ qubits. The more compact representation with $n$ qubits for a chain $N=2^n$ nodes is discussed elsewhere, _e.g._, see arXiv:1710.03615 \\[quant-ph\\](2017) with [tutorial about topological quantum walk](../../../terra/qis_adv/topological_quantum_walk.ipynb).\n",
    "\n",
    "### Chain model\n",
    "\n",
    "The nodes chain are mapped into states with single unit in computational basis\n",
    "\n",
    "$$|100\\dots 0\\rangle,|010\\dots 0\\rangle,\\dots,|000\\dots1\\rangle.$$\n",
    "\n",
    "Let us denote\n",
    "\n",
    "$$|{\\underline k}\\rangle \\equiv |{\\underbrace{0\\ldots 0}_{k-1}\\,}1\\underbrace{0\\ldots 0}_{n-k}\\rangle,\n",
    "\\quad k=1,\\ldots,n.$$\n",
    "\n",
    "The method also may be extended for $m>1$ particles using states with $m$ units in computational basis. \n",
    "\n",
    "### Single link \n",
    "\n",
    "Let us start with with one particle on a chain with two nodes. By definition, the evolution may affect only states \n",
    "$|{\\underline 1}\\rangle \\equiv |10\\rangle$ and \n",
    "$|{\\underline 2}\\rangle \\equiv |01\\rangle$. \n",
    "The two-gate for such evolution is represented by some matrix\n",
    "\n",
    "$$\n",
    "M_u \\equiv \\begin{pmatrix}\n",
    "1 & 0 & 0 & 0 \\\\\n",
    "0 & u_{11} & u_{12} & 0 \\\\\n",
    "0 & u_{21} & u_{22} & 0 \\\\\n",
    "0 & 0 & 0 & 1 \n",
    "\\end{pmatrix}, \n",
    "$$\n",
    "where $u_{jk}$ is unitary matrix.\n",
    "\n",
    "The chain with two nodes corresponds to a link in a qubit chain and such a representation is directly extended into a sequence of two-qubit gates on a chain.\n",
    "\n",
    "### Relation with matchgates\n",
    "\n",
    "A _matchgate_ is defined by two unitary matrices $u$ and $u'$ with $\\det{u'}=\\det{u}$\n",
    "\n",
    "$$\n",
    "M(u,u') \\equiv \\begin{pmatrix}\n",
    "u'_{11} & 0 & 0 & u'_{12} \\\\\n",
    "0 & u_{11} & u_{12} & 0 \\\\\n",
    "0 & u_{21} & u_{22} & 0 \\\\\n",
    "u'_{21} & 0 & 0 & u'_{22} \n",
    "\\end{pmatrix}\n",
    "$$\n",
    "\n",
    "The $M_u$ is particular case of matchgate $M(u,{\\bf 1})$ with \n",
    "$u' = \\begin{pmatrix}1&0\\\\0&1\\end{pmatrix}.$ \n",
    "\n",
    "A quantum circuit with _matchgates_ acting on neighboring qubits (_aka_ matchcircuit) may be effectively modeled on a classical computer.\n",
    "So, such circuits may be used for testing of quantum computers with many qubits.\n",
    "\n",
    "The $M_u$ also respects number of units in computational basis and so can be used for modeling of distribution of states or quantum walks along a chains in agreement with model defined earlier. State distribution along a quantum network with $n$ qubits in such a case may be mapped into corresponding scalar chain with $n$ nodes.\n",
    "\n",
    "### Adaptation to Qiskit\n",
    "\n",
    "Because of $\\det(u)=1$ the gate $M_u$ may be described with three angles similar with $u3$ and $C_{u3}$ gate in QISKit. \n",
    "Let us denote that as\n",
    "\n",
    "$$\n",
    "  M_u \\equiv M_{u3}(\\theta, \\phi, \\lambda)  \\equiv \n",
    "    \\begin{pmatrix}\\\n",
    "    1 & 0 & 0 & 0\\\\\n",
    "    0 & e^{-i(\\phi+\\lambda)/2}\\cos(\\theta/2) & -e^{-i(\\phi-\\lambda)/2}\\sin(\\theta/2) &  0\\\\\n",
    "   0 & e^{i(\\phi-\\lambda)/2}\\sin(\\theta/2)  & e^{i(\\phi+\\lambda)/2}\\cos(\\theta/2)    & 0\\\\\n",
    "   0 & 0 & 0 & 1\\\\\n",
    "   \\end{pmatrix}.\n",
    "$$\n",
    "\n",
    "The gate $M_{u3}$ may be written as a procedure on OpenQASM 2.0\n",
    "\n",
    "    mu3 (theta, phi, lambda) a,b {\n",
    "    cx a,b;\n",
    "    cu3 (theta,phi,lambda) b,a;\n",
    "    cx a,b;\n",
    "    }\n",
    "\n",
    "Similar method is used further with Qiskit, however it may be not very optimal for hardware."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Staggered quantum walk\n",
    "\n",
    "Let us consider as an example the staggered walk described earlier in simpler model of [scalar quantum chain](scalar_chain.ipynb). The sequences of gates representing modifications of partitions $S'_1$ and $S_2$ \n",
    "now should use $4 \\times 4$ analogues of $2 \\times 2$ matrices applied earlier to neighboring nodes of chain\n",
    "\n",
    "$$\n",
    "  m_2 \\equiv M_{i S_2} = \n",
    "    \\begin{pmatrix}\\\n",
    "    1 & 0 & 0 & 0\\\\\n",
    "    0 & 0 & i &  0\\\\\n",
    "   0 & i  & 0 & 0\\\\\n",
    "   0 & 0 & 0 & 1\\\\\n",
    "   \\end{pmatrix} = M_{u3}(\\pi/2,0,0).\n",
    "$$\n",
    "\n",
    "$$\n",
    "  m_1 \\equiv M_{S'_1} = \n",
    "    \\begin{pmatrix}\\\n",
    "    1 & 0 & 0 & 0\\\\\n",
    "    0 & 1/\\sqrt{2} & -1/\\sqrt{2} &  0\\\\\n",
    "   0 &  1/\\sqrt{2}  & 1/\\sqrt{2} & 0\\\\\n",
    "   0 & 0 & 0 & 1\\\\\n",
    "   \\end{pmatrix} = M_{u3}(\\pi,\\pi,0).\n",
    "$$\n",
    "\n",
    "See notebook with [modeling of qubit chain](qubit_chain_mod.ipynb) using Qiskit."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
